package com.bdth.bdthiss.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.bdth.bdthiss.entity.Excelgoods;
import com.bdth.bdthiss.entity.User;
import com.bdth.bdthiss.entity.Userop;
import com.bdth.bdthiss.mapper.ExcelgoodsMapper;
import com.bdth.bdthiss.mapper.UserMapper;
import com.bdth.bdthiss.service.ExcelgoodsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.bdth.bdthiss.vo.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LGP
 * @since 2020-04-06
 */
@Service
public class ExcelgoodsServiceImpl extends ServiceImpl<ExcelgoodsMapper, Excelgoods> implements ExcelgoodsService {

    @Autowired
    private ExcelgoodsMapper excelgoodsMapper;

    @Override
    public Page<Excelgoods> listPages(Pagination pagination, Map<String, Object> query) {
        EntityWrapper<Excelgoods> entityWrapper = new EntityWrapper<>();
//        if((String) param.get("username")!=null) {
//            entityWrapper.like("username", (String) param.get("username"));
//        }
//        if((String) param.get("nickname")!=null){
//            entityWrapper.like("nickname", (String) param.get("nickname"));
//        }
//        if((String) param.get("email")!=null) {
//            entityWrapper.like("email", (String) param.get("email"));
//        }
//        if((String) param.get("departids")!=null) {
//            entityWrapper.gt("departid",0);
//            entityWrapper.in("departid", (String) param.get("departids"));
//        }
        if(pagination.getOrder()!=null) {
            if (pagination.getOrder().toLowerCase().equals("asc")){
                entityWrapper.orderBy(pagination.getSort(), true);
            }else{
                entityWrapper.orderBy(pagination.getSort(), false);
            }
        }
        Page<Excelgoods> page = new Page<>(pagination.getPage()==null?1:pagination.getPage(),
                pagination.getRows()==null?20:pagination.getRows());

        List<Excelgoods> items = excelgoodsMapper.selectPage(page,entityWrapper);
        page.setRecords(items);
        return page;
    }
}
